home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MAGS.ZIP / VLAD#3.ZIP / ARTICLE.3_4 < prev    next >
Encoding:
Text File  |  1995-01-26  |  2.0 KB  |  81 lines

  1.  
  2. ;
  3. ;       Writing to the hard disk using the ports!     by qark
  4. ;       +---------------------------------------+
  5. ;
  6. ;  The only differences between reading and writing using the ports is
  7. ;  that 30h is sent to the command register, and instead of INSW you
  8. ;  OUTSW.  
  9. ;
  10. ;  I chose to write to sector 2 because some idiot would trash their MBR
  11. ;  by running this.
  12. ;
  13.  
  14.     mov     dx,1f6h         ;Drive and head port
  15.     mov     al,0a0h         ;Drive 0, head 0
  16.     out     dx,al
  17.  
  18.     mov     dx,1f2h         ;Sector count port
  19.     mov     al,1            ;Write one sector
  20.     out     dx,al
  21.  
  22.     mov     dx,1f3h         ;Sector number port
  23.     mov     al,2            ;Wrote to sector two
  24.     out     dx,al
  25.  
  26.     mov     dx,1f4h         ;Cylinder low port
  27.     mov     al,0            ;Cylinder 0
  28.     out     dx,al
  29.  
  30.     mov     dx,1f5h         ;Cylinder high port
  31.     mov     al,0            ;The rest of the cylinder 0
  32.     out     dx,al
  33.  
  34.     mov     dx,1f7h         ;Command port
  35.     mov     al,30h          ;Write with retry.
  36.     out     dx,al
  37. oogle:
  38.     in      al,dx
  39.     test    al,8            ;Wait for sector buffer ready.
  40.     jz      oogle
  41.     
  42.     mov     cx,512/2        ;One sector /2
  43.     mov     si,offset buffer
  44.     mov     dx,1f0h         ;Data port - data comes in and out of here.
  45.     rep     outsw           ;Send it.
  46.  
  47. ;    ------------
  48.  
  49.     mov     ax,201h                 ;We'll read in sector 2 using
  50.     mov     bx,offset buffer2       ;int13h and see if we are successful.
  51.     mov     cx,2
  52.     mov     dx,80h
  53.     int     13h
  54.  
  55.     mov     cx,512
  56.     mov     si,offset buffer
  57.     mov     di,offset buffer2
  58.     repe    cmpsb                   ;Compare the buffers.
  59.     jne     failure
  60.  
  61.     mov     ah,9
  62.     mov     dx,offset write_msg
  63.     int     21h
  64.     jmp     w_exit
  65. failure:
  66.     mov     ah,9
  67.     mov     dx,offset fail
  68.     int     21h
  69.     
  70. w_exit:
  71.     mov     ax,4c00h        ;Exit the program
  72.     int     21h
  73.     
  74.     write_msg       db      'Sector two written to using the ports.$'
  75.     fail            db      'Writing using ports failed.$'
  76.  
  77. buffer  db      512 dup ('A')
  78. buffer2 db      512 dup ('D')
  79.  
  80.  
  81.